package org.brisling.common.queryService;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.brisling.base.service.AbstractBaseQueryService;
import org.brisling.common.ConstSysParam;
import org.brisling.common.domain.InquiryDomain;
import org.brisling.common.util.StringUtil;
import org.brisling.sysman.queryService.QueryDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 
 * <p>Title: QueryInquiryService</p>
 * <p>Description: 通用质询查询服务类</p>
 * <p>Company: tongking</p>
 * @author jackson wang
 * @since 1.0
 * @version 1.0
 * @date 2017年4月14日 上午5:02:30
 */

@RestController
@RequestMapping("/inquiry/query")
public class QueryInquiryService extends AbstractBaseQueryService<InquiryDomain>{
	
	@Autowired
	protected QueryDictionaryService dicService;
	
	private static String commonSubsystem= "sysman";
	
	public QueryInquiryService(){
		this.clazz = InquiryDomain.class;
		this.moduleName = ConstSysParam.MODULE_INQUIRY_COMMON;
		this.tableName = ConstSysParam.VIEW_PREFIX + this.moduleName;
	}
	
	@PersistenceContext(unitName=ConstSysParam.SUBSYSTEM_SYSMAN)
	@Autowired
	protected void setEntityManager(EntityManager entityManager){
		this.entityManager = entityManager;		
	}
	
	/**
	 * 根据流程实例id查找业务记录
	 * @param flowInstId		流程实例id
	 */
	@RequestMapping("/getOneByFlowInstId.action")
	public InquiryDomain getOneByFlowInstId(
			@RequestParam(value="flowInstId",required=false) String flowInstId){
		
		if(flowInstId!=null){
			String sql = dicService.getSqlByBizcode("inquiry_query_singal");
			if(sql!=null){
				Map<String,Object> map = new HashMap<String,Object>();
				map.put("flowinstid", flowInstId);
				sql = StringUtil.formatSql(sql, map);				
				return super.getOneBySql(sql);
			}
		}
		return null;
	}
}
